//4：传闻StringBuilder比StringBuffer快,
//比较一下，输出你的比较结果（拼接10万个相同的字符串，比较时间）。
public class Str {
    public static void main(String[] args) {
        StringBuilder a = new StringBuilder();
        StringBuffer b = new StringBuffer();
        long start1 = System.nanoTime();
        for (int i = 0; i < 1000000; i++) {
            a = a.append("z");
        }
        long stop1 = System.nanoTime();
        long time1 = stop1 - start1;
        long start2 = System.nanoTime();
        for (int i = 0; i < 1000000; i++) {
            b = b.append("z");
        }
        long stop2 = System.nanoTime();
        long time2 = stop2 - start2;
        System.out.println("StringBuilder的时间为：" + time1 + "\nStringBuffer的时间为：" + time2);
        if (time1 > time2) {
            System.out.println("StringBuffer更快!");
        } else {
            System.out.println("StringBuilder更快!");
        }
    }
}